package drds.common.db.xml_mapping.script.defaults;

import drds.common.db.xml_mapping.builder.BuilderException;
import drds.common.db.xml_mapping.mapping.SqlSource;
import drds.common.db.xml_mapping.parsing.XmlNode;
import drds.common.db.xml_mapping.script.xml_tags.XMLLanguageDriver;
import drds.common.db.xml_mapping.session.Configuration;


public class RawLanguageDriver extends XMLLanguageDriver {

  @Override
  public SqlSource createSqlSource(Configuration configuration, XmlNode script, Class<?> parameterType) {
    SqlSource source = super.createSqlSource(configuration, script, parameterType);
    checkIsNotDynamic(source);
    return source;
  }

  @Override
  public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
    SqlSource source = super.createSqlSource(configuration, script, parameterType);
    checkIsNotDynamic(source);
    return source;
  }

  private void checkIsNotDynamic(SqlSource source) {
    if (!RawSqlSource.class.equals(source.getClass())) {
      throw new BuilderException("Dynamic content is not allowed when using RAW language");
    }
  }

}
